package com.llt.system.controller.sysuser;


import com.llt.common.core.constants.HttpConstants;
import com.llt.common.core.controller.BaseController;
import com.llt.common.core.domain.R;
import com.llt.common.core.domain.TableDataInfo;
import com.llt.system.domain.sysuser.dto.LoginDTO;
import com.llt.system.domain.sysuser.dto.SuserQueryDTO;
import com.llt.system.domain.sysuser.dto.SysUserSaveDTO;
import com.llt.system.domain.sysuser.vo.LoginUserVO;
import com.llt.system.domain.sysuser.vo.SysUserVO;
import com.llt.system.domain.user.dto.UserQueryDTO;
import com.llt.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author llt
 * @since 2024-08-06
 */
@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员相关接口")
public class SysUserController extends BaseController {

    @Autowired
    private  ISysUserService sysUserService;

    /**
     * 登陆
     */
    @PostMapping("/login")
    public R<String> login(@RequestBody LoginDTO loginDTO){
        return sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }

    /**
     * 退出登陆
     */
    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.logout(token);
    }

    /**
     * 获取用户信息
     */
    @GetMapping("/info")
    public R<LoginUserVO>  info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }

    /**
     * 添加管理员
     */
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserSaveDTO sysUserSaveDTO) {
        return toR(sysUserService.add(sysUserSaveDTO));
    }

    /**
     * 获取管理员列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SuserQueryDTO dto) {
        return getTableDataInfo(sysUserService.list(dto));
    }

    /**
     * 删除用户
     */
    @Operation(summary = "删除用户", description = "通过用户id删除用户")
    @DeleteMapping("/{userId}")
    public R<Void> delete(@PathVariable Long userId) {
        // todo
        return null;
    }

    @Operation(summary = "用户详情", description = "根据查询条件查询用户详情")
    @GetMapping("/detail")
    public R<SysUserVO> detail(@RequestParam(required = true) Long userId, @RequestParam(required = false) String sex) {
        // todo
        return null;
    }
}
